// **********************************************************************
//                            Project Nitro
//                        ---------------------
//
//  File        : CarResources.h
//  Description : Car resources
//  Author      : Guillaume Delhumeau <guillaume.delhumeau@gmail.com>
//  License     : GNU General Public License 3
//
// **********************************************************************

#include "CarResources.h"

/************************************************************************/
/* Constructor                                                          */
/************************************************************************/
CarResources::CarResources():
_loaded(false)
{

}

/************************************************************************/
/* Load resources from CRES file                                        */
/************************************************************************/
void CarResources::load_resources(Screen & screen, std::string filename)
{
	// Making virtual file systems
	CL_VirtualFileSystem vfs(filename, true);
	CL_VirtualDirectory vd(vfs, "./");	
	CL_ResourceManager resources("car_resources.xml",vd);

	// Loading sprites
	_body = CL_Sprite(screen.get_gc(), "sprites/body", &resources);
	_wheel = CL_Sprite(screen.get_gc(), "sprites/wheel", &resources);
	
	// Loading informations
	_center_x = resources.get_integer_resource("informations/center-x", 0);
	_center_z = resources.get_integer_resource("informations/center-z", 0);
	_left_wheel_x = resources.get_integer_resource("informations/left-wheel-x", 0);
	_left_wheel_z = resources.get_integer_resource("informations/left-wheel-z", 0);
	_right_wheel_x = resources.get_integer_resource("informations/right-wheel-x", 0);
	_right_wheel_z = resources.get_integer_resource("informations/right-wheel-z", 0);

	// Settings
	_body.set_alignment(origin_top_left, -_center_x, -_center_z);
	_wheel.set_alignment(origin_top_left, -_wheel.get_width()/2, -_wheel.get_height()/2);

	_loaded = true;

}
